﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using NetworkSupervisor.Helper;

namespace NetworkSupervisor
{
    public partial class FormConnSetup : DevExpress.XtraEditors.XtraForm
    {
        private ConnectionInfo info = null;

        public FormConnSetup()
        {
            InitializeComponent();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void FormConnSetup_Shown(object sender, EventArgs e)
        {
            cbType.Text = info.Type;
            txtDatabase.Text = info.Database;
            txtPassword.Text = info.Password;
            txtServer.Text = info.Server;
            txtUserid.Text = info.Userid;
        }

        private void FormConnSetup_Load(object sender, EventArgs e)
        {
            Icon = Properties.Resources.app;
            info = new ConnectionInfo();
        }

        private void cbType_SelectedIndexChanged(object sender, EventArgs e)
        {
            string type = cbType.Text;
            if (type == "mssql")
            {
                txtPassword.Enabled = txtServer.Enabled = txtUserid.Enabled = true;
                txtDatabase.Text = "NetworkSupervisor";
            }
            if (type == "access")
            {
                txtPassword.Enabled = txtServer.Enabled = txtUserid.Enabled = false;
                txtDatabase.Text = "data.mdb";
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            info.Type = cbType.Text;
            info.Database = txtDatabase.Text;
            info.Password = txtPassword.Text;
            info.Server = txtServer.Text;
            info.Userid = txtUserid.Text;
            info.UpdateConnectionString();


        }
    }
}